<?php
            include_once("functions/database.php");
            include_once("functions/page.php");
            include_once("functions/is_login.php");
?>
<form action="" method="post" name="searchfrm" >
    <input type="checkbox" name="ck_class" value="yes" >
    按照类别浏览：
    <select name="category_id">
            <option value="0">全部类别</option>
        <?php
            
            get_connection();
            $result_set = mysql_query("select * from category");
            close_connection();
            while($row = mysql_fetch_array($result_set)){
        ?>
            <option value="<?php echo $row['category_id'];?>"><?php echo $row['name'];?></option>
        <?php
            }
        ?>
    </select>
    <input type="submit" value="浏  览">
</form>
<?php
    //先决条件
    $ckclass=$_POST['ck_class'];
    $classquery=$_POST['category_id'];
    $f=false;
    if ("yes"==$ckclass) {
        //echo "ckcheck";
        $f=true;
    } 
    if (!$f) {
        return ;
    } else {
        //echo "enter func";
        if ($classquery=="0") {
            $search_sql = "select * from news where 1=1";
            get_connection();
            $resultset = mysql_query($search_sql);
            if(mysql_num_rows($resultset)==0){
                //echo "enter null";
                echo "暂无信息";
                return;
            };
            ?>
            <table>
            <?php
            while($row = mysql_fetch_array($resultset)){
//					echo "enter all"
            ?>
            <tr>
            <td>
            <a href="index.php?url=news_detail.php&news_id=<?php echo $row['news_id']?>"><?php echo mb_strcut($row['title'],0,40,"gbk")?></a>
            </td>
            <?php
            if(is_login()){
            ?>
            <td>
            <a href="index.php?url=news_edit.php&news_id=<?php echo $row['news_id']?>">编辑</a>
            </td>
            <td>
            <a href="index.php?url=news_delete.php&news_id=<?php echo $row['news_id']?>" onclick="return confirm('确定删除吗？');">删除</a>
            </td>
            <?php
                }
            ?>
            </tr>
            <?php
            }
            ?>
            </table>
            
    <?php	close_connection();
            } else {
            $search_sql = "select * from news where category_id=$classquery";
            get_connection();
            $resultset = mysql_query($search_sql);
            if(mysql_num_rows($resultset)==0){
                //echo "enter null";
                echo "暂无信息";
                return;
            };
            ?>
            <table>
            <?php
            while($row = mysql_fetch_array($resultset)){
//					echo "enter all"
            ?>
            <tr>
            <td>
            <a href="index.php?url=news_detail.php&news_id=<?php echo $row['news_id']?>"><?php echo mb_strcut($row['title'],0,40,"gbk")?></a>
            </td>
            <?php
            if(is_login()){
            ?>
            <td>
            <a href="index.php?url=news_edit.php&news_id=<?php echo $row['news_id']?>">编辑</a>
            </td>
            <td>
            <a href="index.php?url=news_delete.php&news_id=<?php echo $row['news_id']?>" onclick="return confirm('确定删除吗？');">删除</a>
            </td>
            <?php
                }
            ?>
            </tr>
            <?php
            }
            ?>
            </table>
            
    <?php	close_connection();
            
        }
                
    }
    
     
?>